/**
*  Class describing a confirm select frame
*
*  @copyright 2016
*/

/**
*  Dependencies
*/
#include "confirmframe.h"


/**
*  Set up namespace
*/
namespace AMQP{

/**
*  Class implementation
*/
class ConfirmSelectFrame : public ConfirmFrame
{
private:

	/**
	*  whether to wait for a response
	*  @var    BooleanSet
	*/
	BooleanSet _noWait;

protected:
	/**
	*  Encode a frame on a string buffer
	*
	*  @param   buffer  buffer to write frame to
	*/
	virtual void fill(OutBuffer& buffer) const override
	{
		// call base
		ConfirmFrame::fill(buffer);

		// add booleans
		_noWait.fill(buffer);
	}

public:
	/**
	*  Construct a confirm select frame from a received frame
	*
	*  @param  frame   received frame to parse
	*/
	ConfirmSelectFrame(ReceivedFrame &frame) : ConfirmFrame(frame), _noWait(frame) {}

	/**
	*  Construct confirm select frame frame
	*
	*  @param  channel         Channel identifier
	*  @param  noWait          whether to wait for a response.
	*/
	ConfirmSelectFrame(uint16_t channel, bool noWait = false) :
		ConfirmFrame(channel,  1),    //1 for bool
		_noWait(noWait) {}

	/**
	*  Destructor
	*/
	virtual ~ConfirmSelectFrame() {}

	/**
	*  Is this a synchronous frame?
	*
	*  After a synchronous frame no more frames may be
	*  sent until the accompanying -ok frame arrives
	*/
	bool synchronous() const override
	{
		// we are synchronous when the nowait option is not used
		return !noWait();
	}

	/**
	*  Return the method ID
	*  @return  uint16_t
	*/
	virtual uint16_t methodID() const override
	{
		return 10;
	}

	/**
	*  Return whether to wait for a response
	*  @return  boolean
	*/
	const bool noWait() const
	{
		return _noWait.get(0);
	}
};

	/**
	*  end namespace
	*/
}

